/**
 *
 */
package com.googlecode.bip.entity;

import java.io.Serializable;

/**
 * Entry for 'local' table
 *
 * @author Claude CHOISNET
 */
public class Local
    implements Serializable, ILocal
{
    private static final long serialVersionUID = 1L;
    private String idlocal;
    private String name;

    /**
     * Create a NOT initialized Local
     */
    public Local()
    {
    }

    /**
     * Create a initialized Local
     */
    public Local(
            final String idlocal,
            final String name
            )
    {
        setIdLocal( idlocal );
        setName( name );
    }

    /**
     * Set idlocal for Local
     *
     * @param idlocal idlocal to set (lower case, 2 characters)
     * @throws IllegalArgumentException if idlocal is not valid
     * @throws NullPointerException if idlocal is null
     */
    public void setIdLocal( String idlocal )
        throws IllegalArgumentException, NullPointerException
    {
         idlocal = idlocal.trim().toLowerCase();

        if( idlocal.length() != 2 ) {
            throw new IllegalArgumentException();
            }

        this.idlocal = idlocal;
    }

    /* (non-Javadoc)
     * @see com.googlecode.bip.entity.ILocal#getIdLocal()
     */
    @Override
    public String getIdLocal()
    {
        return idlocal;
    }

    /**
     * Set name for Local
     * @param name Name to set
     */
    public void setName( String name )
    {
        this.name = name;
    }

    /* (non-Javadoc)
     * @see com.googlecode.bip.entity.ILocal#getName()
     */
    @Override
    public String getName()
    {
        return name;
    }

    /* (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString()
    {
        StringBuilder builder = new StringBuilder();

        builder.append( "Local [idlocal=" ).append( idlocal )
               .append( ", name=" ).append( name )
               .append( "]" );

        return builder.toString();
    }

}
